﻿using System;


namespace DailyFx.IndicatorExtension
{

	public class VWAP : Index
	{
		public VWAP ( int n) : base ( 1, n )
		{
			this.Pximpl = new HyperVector(n, "px", Layout.OVERLAY, Stylus.LINE, 0);
		}


        public override void Cook ( BarSeries series )
		{

			decimal wp = 0.0m;
			decimal vol = 0.0m;

			int i = 0;
			foreach ( Bar b in series ) // This'd be a intraday bar series !!
			{
                wp += b.Typical * b.Vol;
				vol += b.Vol;

				this.Pximpl [i] = (wp / vol);
				i++ ;
			}
		}


        public override string Family
        {
            get { return "Volume-Weighted average Price"; }
        }

        public override string Label
        {
            get { return "VWAP"; }
        }


    
		public HyperVector Pximpl
		{
			get {
				return _children [ 0];
			}
			private set {
				_children [0] = value;
			}
		}
     
	}
}
